/**
 * 流程定义
 * @author luguoxiang
 * @date 2025-08-02
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { BaseEntity, IConfigSchema } from '@/soar';
import { basePath } from './api';
import { MenuComponent } from '@/types/interface';

export interface SoarProcess extends BaseEntity {
  /** 主键 */
  id?: string;
  /** 编码 */
  code?: string;
  /** 名称 */
  name?: string;
  /** 图标 */
  logo?: string;
  /** 标题模板 */
  titleTemplate?: string;
  /** 节点信息 */
  nodes?: any[];
  /** 当前部署版本 */
  versionId?: string;
  /** 最后部署时间 */
  lastDeployTime?: string;
  /** 是否禁用（0否，1是） */
  disabled?: boolean;
}

const fieldList: IConfigSchema<SoarProcess>[] = [
  {
    field: 'logo',
    label: '图标',
    dataType: 'img',
    params: 'url',
    search: false,
    table: {
      width: 60,
    },
  },
  {
    field: 'code',
    label: '编码',
    dataType: 'string',
    form: {
      rules: true,
    },
  },
  {
    field: 'name',
    label: '名称',
    dataType: 'string',
    form: {
      rules: true,
    },
  },
  {
    field: 'titleTemplate',
    label: '标题模板',
    dataType: 'string',
    search: false,
  },
  {
    field: 'disabled',
    label: '是否禁用',
    dataType: 'boolean',
    table: {
      width: 80,
    },
  },
  {
    field: 'updateTime',
    label: '更新时间',
    dataType: 'datetime',
    form: false,
    table: {
      width: 160,
      sorter: true,
    },
  },
  {
    field: 'lastDeployTime',
    label: '最新部署时间',
    dataType: 'datetime',
    form: false,
    table: {
      width: 160,
      sorter: true,
    },
  },
];

export default fieldList;

/**
 * 组件配置（用于生成菜单数据）
 */
export const COMPONENTS: MenuComponent[] = [
  {
    title: '流程定义',
    component: () => import('./List.vue'),
    sort: 10,
    keepalive: true,
    icon: '',
    permits: [`GET${basePath}/query`],
    elements: [
      { title: '新增', code: 'create', permits: [`POST${basePath}/create`] },
      { title: '更新', code: 'update', permits: [`POST${basePath}/update`, `GET${basePath}/detail`] },
      { title: '删除', code: 'remove', permits: [`POST${basePath}/remove`] },
      { title: '部署', code: 'deploy', permits: [`POST${basePath}/deploy`] },
      { title: '详情', code: 'detail', permits: [`GET${basePath}/detail`] },
      { title: '导入', code: 'import', permits: [`POST${basePath}/import`] },
      { title: '导出', code: 'export', permits: [`GET${basePath}/export`] },
    ],
  },
];
